/**
 * Copyright (C) 2013 Denatics Development
 *
 * Programmed by David Tiersch <dtiersch@denatics.com>
 *
 * This file is part of B0mberman.
 *
 * B0mberman is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * B0mberman is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with B0mberman. If not, see <http://www.gnu.org/licenses/>.
 */
package com.denatics.bomberman.tools;

import com.denatics.bomberman.Config;

/**
 * This class centralizes the general Debug-Output.
 *
 * @author David Tiersch <dtiersch@denatics.com>
 */
public abstract class Debugger {

    /**
     * Debug-Level.
     */
    public enum LEVEL {
        /**
         * Show Errors.
         */
        ERROR,
        /**
         * Activates Detailed view for Informations inluding class and
         * line-number.
         */
        DETAIL,
        /**
         * Show Informations about the current FPS-Rate.
         */
        FPS,
        /**
         * Show Informations about Sprites being added/removed.
         */
        SPRITE,
        /**
         * Show Informations about pressed keys.
         */
        KEYS,
        /**
         * Show Informations about the StartUp-process.
         */
        STARTUP;

        /**
         * Stores, if the Debug-Option is set.
         */
        private boolean set;

        /**
         * Sets, if the Debug-Level is active.
         *
         * @param active
         *            true if active
         */
        public void set(final boolean active) {
            this.set = active;
        }

        /**
         * Returns if the Debug-Option is set active.
         *
         * @return true if active
         */
        public boolean active() {
            return this.set;
        }
    };

    /**
     * Empty, private constructor to forbid Creating an Instance of this class.
     */
    private Debugger() {
        // do nothing
    }

    /**
     * Prints a message on std_err.
     *
     * @param message
     *            Message to be printed
     */
    public static void printError(final String message) {
        if (LEVEL.ERROR.active()) {
            final Throwable throwable = new Throwable();
            final String originClass =
                    (throwable.getStackTrace())[1].getClassName();
            final int originLine =
                    (throwable.getStackTrace())[1].getLineNumber();

            System.err.println("Error: [" + originClass + ":" + originLine
                    + "] " + message);
        }
    }

    /**
     * Prints a message on std_out.
     *
     * @param level
     *            Type of the Info-Message
     * @param message
     *            Message to be printed
     */
    public static void printInfo(final LEVEL level, final String message) {
        if (level.active()) {
            if (LEVEL.DETAIL.active()) {
                final Throwable throwable = new Throwable();
                final String originClass =
                        (throwable.getStackTrace())[1].getClassName();
                final int originLine =
                        (throwable.getStackTrace())[1].getLineNumber();

                System.out.print("Info: [" + originClass + ":" + originLine
                        + "] ");
            }
            System.out.println(message);
        }
    }

    /**
     * Intializes the Debugger to load the Config which values has to be
     * printed.
     */
    public static void init() {
        for (LEVEL level : Config.DEBUG) {
            level.set(true);
        }
    }
}
